import json
import math


class Shape:
    def __init__(self,*edges):
        self.edges = edges

class Triangle(Shape):
    def __init__(self,*edges):
        super().__init__(*edges)
        if len(self.edges) !=3:
            raise Exception("输入的边长个数不为3")
    def getArea(self):
        a=self.edges[0]
        b=self.edges[1]
        c=self.edges[2]
        p = (a+b+c) / 2
        return math.pow(p*(p-a)*(p-b)*(p-c),0.5)

class Rectangle(Shape):
    def __init__(self,*edges):
        super().__init__(*edges)
        if len(self.edges) !=2:
            raise Exception("输入的边长个数不为2")
    def getArea(self):
        a=self.edges[0]
        b=self.edges[1]
        return a*b

class Circle(Shape):
    def __init__(self,*edges):
        super().__init__(*edges)
        if len(self.edges) !=1:
            raise Exception("输入的半径个数不为1")
    def getArea(self):
        r=self.edges[0]
        return math.pi*r*r
    def serialization(self):
        return json.dumps({'r':self.edges[0],'area':self.getArea()})

# t = Triangle(3,4,5)
# r = Rectangle(4,5)
# c = Circle(3)
#
# print(t.getArea())
# print(r.getArea())
# print(c.getArea())
# print(c.serialization())


class Shape2:
    def getArea(self):
        raise NotImplementedError('为实现该函数')


class Triangle2(Shape2):
    def __init__(self, a, b, c):
        self._a = a
        self._b = b
        self._c = c
        self._p = (a+b+c) / 2

    def getArea(self):
        self._area = math.sqrt(self._p*(self._p-self._a)*(self._p-self._b)*(self._p-self._c))
        return self._area

class Rectangle2(Shape2):
    def __init__(self, a, b):
        self._a = a
        self._b = b
    def getArea(self):
        self._area = self._a*self._b
        return self._area

class Circle2(Shape2):
    def __init__(self, r):
        self._r = r
    def getArea(self):
        self._area = math.pi*self._r*self._r
        return self._area

t = Triangle2(3,4,5)
r = Rectangle2(4,5)
c = Circle2(3)
print(t.getArea())
print(r.getArea())
print(c.getArea())

class  SerializationMixin:
    def serialization(self):
        return json.dumps(self.__dict__)

class SerializationCircle2(SerializationMixin,Circle2):pass

c2 = SerializationCircle2(3)
print(c2.serialization())
print(c2.getArea())
print(c2.serialization())
